package com.lhj.es.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author linghaijin
 * @date 2020-05-06 14:44
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BaseResult<T> {

    private Integer code;

    private Boolean success;

    private String msg;

    private T data;

    public static BaseResult ok() {
        BaseResult result = new BaseResult();
        result.setCode(200);
        result.setSuccess(true);
        result.setMsg("SUCCESS");
        return result;
    }

    public static BaseResult ok(Object data) {
        BaseResult result = new BaseResult();
        result.setCode(200);
        result.setSuccess(true);
        result.setMsg("SUCCESS");
        result.setData(data);
        return result;
    }

    public static BaseResult error(String msg) {
        BaseResult result = new BaseResult();
        result.setCode(200);
        result.setSuccess(false);
        result.setMsg(msg);
        return result;
    }

    public static BaseResult error() {
        BaseResult result = new BaseResult();
        result.setCode(200);
        result.setSuccess(false);
        result.setMsg("FAILED");
        return result;
    }
}
